package org.minuframework.kdniao.logistics;

import java.io.File;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.minuframework.file.FileUtils;
import org.minuframework.utils.ParamUtils;
import com.google.common.collect.Maps;

public class KdniaoLogisticsConfigurer {

    /**
     * 前缀
     */
    private static final String prefix = "logistics.kdniao";

    private static final String EBusinessID = "EBusinessID";
    private static final String AppKey = "AppKey";

    private static Map<Object, Object> params = Maps.newHashMap();

    public KdniaoLogisticsConfigurer() {
        String pathname = ParamUtils.getPathName("properties/minu.properties");
        File file = new File(pathname);
        params = FileUtils.asMap(file, pathname);
    }

    /**
     * 电商ID
     * 
     * @return 电商ID String
     */
    public String getEBusinessID() {
        return params.containsKey(getKey(EBusinessID)) ? params.get(getKey(EBusinessID)).toString()
                : null;
    }

    /**
     * 电商加密私钥
     * 
     * @return 电商加密私钥 String
     */
    public String getAppKey() {
        return params.containsKey(getKey(AppKey)) ? params.get(getKey(AppKey)).toString() : null;
    }

    public Map<Object, Object> getParams() {
        return params;
    }

    public int size() {
        return params.size();
    }

    public String toString() {
        return params.toString();
    }

    private String getKey(String key) {
        return StringUtils.isNotEmpty(key) ? (prefix + '.' + key) : null;
    }

}
